#ifndef SYMBIANQTPROJECTGENERATOR_H
#define SYMBIANQTPROJECTGENERATOR_H


#include <QObject>
#include <QString>
#include <QStack>
#include <QProcess>
#include <QList>
#include <QSharedPointer>

#include "defines.h"
#include "generatordata.h"
#include "generatoroutputview.h"
#include "hybridplugin.h"

#include "iqtprojectgenerator.h"

class GeneratorOutputView;
class SymbianProcessRunner;

class SymbianQtProjectGenerator : public IQtProjectGenerator
{
    Q_OBJECT

protected:
    //
    // private members
    //

    GeneratorOutputView   & m_outputView;
    GeneratorData           m_generatorData;
    SymbianProcessRunner  * m_processRunner;
    GeneratorPhase          m_currentGeneratorPhase;
    GeneratorTarget         m_generatorTarget;
    QStack<QString>         m_pluginDirs;
    WidgetType              m_resolvedWidgetType;

public:
    //
    // lifetime management
    //
    SymbianQtProjectGenerator(GeneratorOutputView & outputView,
                              QObject             * parent = NULL);
    virtual ~SymbianQtProjectGenerator();

    //
    // public operators
    //
signals:
    void started(GeneratorTarget target);
    void finished(int exitCode);

public:
    virtual IStatusUpdater * createStatusUpdater(QObject * parent = NULL);

    const PlatformType& platform();

    virtual void build(const QString &widgetFile,
                       RcSession     &rcSession);
    virtual void rebuild(RcSession     &rcSession);
    virtual void preview(const QString &widgetFile);
    virtual void closeProject();
    virtual GeneratorOutputView &outputView() const;
    virtual GeneratorData &generatorData();
    virtual GeneratorPhase getCurrentPhase() const;
    virtual GeneratorTarget getTarget() const;
    virtual QString getStatusText() const;

    virtual QWidget * createSettingsWidget(const QString & widgetFile,
                                           QWidget       * parent = NULL) const;
    virtual void saveSettings(QWidget * settingsWidget) const;
    virtual QStringList errorsForTarget(GeneratorTarget generatorTarget) const;

    virtual PkgInstallResult installPkg(const QFileInfo & pkgFile) const;

private slots:
    void qmakeFinished(int exitCode, QProcess::ExitStatus exitStatus);
    void makeFinished(int exitCode, QProcess::ExitStatus exitStatus);
    void makesisFinished(int exitCode, QProcess::ExitStatus exitStatus);
    void widgetFilesCopied(int exitCode, QProcess::ExitStatus exitStatus = QProcess::NormalExit);

protected:
    bool prepareEnvironment(const QString &wgzFile);
    bool prepareEnvironmentForNonWRTWidget();
    void unzipWidgetFile(const QString &wgzFile);
    bool handleWidgetConfigFile();
    void handleWidgetDirectory();
    bool parsePluginsProjectFile();
    bool parseWidgetProjectFile();
    void parseWidgetResourceFile();
    bool updateMainFile();
    bool updateMainWindowFile();
    bool copyHybridapiJs();
    bool copyDisableSelectionCSS();
    bool copyFrameworkAndPluginSrcFiles();
    bool updateFrameworkProjectFile();
    void sniffWidgetType();
    bool registerStatus(bool status);
    bool embedFrameworkSis();
    virtual void startBuild();
    void startPreview();

    void copyWidgetDirectory(const QString &wgzFile); // Uncompress widget file
    bool prepareProject();     // qmake plugins
    void qmakeApplication();   // qmake app
    void makeApplication();    // make app
    void makeSisApplication(); // makesis app

};

#endif // SYMBIANQTPROJECTGENERATOR_H
